<?php

namespace App\Exports;

use App\Models\Question;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;

class QuestionExport implements FromView, ShouldAutoSize
{
    public $question;

    public function __construct(Request $request)
    {

        $this->question = Question::pimp()
            ->with('user:id,username')
            ->with('category:id,name')
            ->paginate($request->input('pageSize'));
    }

    /**
     * @return View
     */
    public function view(): View
    {
        return view('exports.question', [
            'question' => $this->question
        ]);
    }
}
